Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Committed improvements #35

Merged
merged 12 commits into from
Apr 10, 2018
Merged

Conversation

AlexWayfer
Copy link
Contributor

Instead of #31, splitted to separate commits.

Sorry, too hard to make separate PRs: one change rely on another.

I can answer ant questions.

There is Add what you changed to CHANGES.md in the Contributing section of README,
but there is no section for this.
Puma can be managed not only via URL with token, but also via CLI without token.
`:restart_timeout` waits this number of seconds before the next restarting the Puma server (default `1`).
@jc00ke
Copy link
Owner

jc00ke commented Feb 2, 2018

Separate commits is fine, thank you! I'll try to review this weekend. I really appreciate the work you put into this project.

@AlexWayfer
Copy link
Contributor Author

Separate commits is fine, thank you! I'll try to review this weekend.

Thank you!

I really appreciate the work you put into this project.

I've switched our commercial project with Puma to Guard, and I've found some troubles with server management via guard-puma. So, I want to fix them, improve this library, and make our team and anybody else happy :)

CHANGES.md Outdated
@@ -2,6 +2,7 @@

## master

* Don't notify about start when no start
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

'--environment' => options[:environment]
}
puma_options = {
(pumactl ? '--config-file' : '--config') => options[:config],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this syntax. I see what it's doing, but I'd prefer something more straightforward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made private constant with keys and private method for getting right key. What do you think?

puma_options = {
(pumactl ? '--config-file' : '--config') => options[:config],
'--control-token' => @control_token,
(pumactl ? '--control-url' : '--control') => "tcp://#{@control_url}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This is a bit too clever for my tastes 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also changed.

end
[:bind, :threads].each do |opt|
puma_options["--#{opt}"] = options[opt] if options[opt]
%i[bind threads environment].each do |opt|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is there another way these could be checked with out using multiple next's? I find this kind of imperative looping with conditionals to be difficult to reason about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One next I took out into Array#select, but this is double iterating. 🙁

The second next I deleted with else adding.

end

def halt
Net::HTTP.get build_uri('halt')
if pumactl
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like these can be pushed down a level too so we don't have so many of these conditionals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you.

@@ -38,6 +40,8 @@ def start
end

def reload
return if Time.now - @last_restarted < options[:restart_timeout]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add parens to make the order of operations more clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure.

@@ -142,9 +149,13 @@
end

context "with custom :notifications option" do
let(:options) { { notifications: [:restarted] } }
let(:options) do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of the Semantic Rule so let's change to {} instead of do/end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, no problem.

context "without pumactl" do
let(:options) { { pumactl: false } }

let(:uri) do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a proponent of the Semantic Rule for {} vs do/end so for the let's I prefer to use {}.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I didn't mean to make this comment twice. I think it came from having 2 browser tabs open for reviews of different commits. Oops!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were many places with let(:foo) do; end, I replaced all of them.

@jc00ke
Copy link
Owner

jc00ke commented Apr 9, 2018

Thanks @AlexWayfer I'll take a look at this tonight (hopefully)

Meant to review it over the weekend but life got in the way.

@AlexWayfer
Copy link
Contributor Author

Thank you, no problem. Life is important. We can use a fork for a while.

Copy link
Owner

@jc00ke jc00ke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment. Thanks again for all of your contributions!

true => {
config: '--config-file',
control_url: '--control-url'
}.freeze,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These inner hashes don't also need to be frozen. The outer hash being frozen freezes them. ❄️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even Strings in frozen Hashes not frozen, as you can see in this example. So, we maybe should freeze '--config-file' and other strings.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I must have mistyped something in a previous IRB session.

I don't think it's really necessay to deep freeze the whole thing anyway, at least not right now (given no real issues on it)

@jc00ke jc00ke merged commit f662b8f into jc00ke:master Apr 10, 2018
jc00ke added a commit that referenced this pull request Apr 10, 2018
@AlexWayfer AlexWayfer deleted the committed_improvements branch April 10, 2018 17:39
@AlexWayfer
Copy link
Contributor Author

Hooray! Thank you! 🎉

I'll come back with new changes. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants